// import { Select } from "antd";
import "./index.less";
import { useTranslation } from "react-i18next";
import { BasicTable, useTable, FormSchema, BasicColumn } from "@/components/Table";
import Toolbar from "@/components/ViewComponents/Toolbar";
import { useDrawer } from "@/components/Drawer";
import CreareVaccinate from "./components/creareVaccinate";
import { useState } from "react";
import { BasicForm, useForm } from "@/components/Form";
let temporarily: any = [];
export default function vaccination_certificate() {
	const { t } = useTranslation();
	const [data, setData] = useState([
		{
			dt_date: "555555555",
			patient_id: "1",
			full_name: "张三",
			birthyear: "2024-01-05",
			gender: "男",
			phone_numb: "133554466",
			citizen_id: "sanasn",
			pat_address: "gjdtrefawetyetgrshrsjsrsaddfgh",
			workplace: "gjdtrefawetyetgrshrsjsrsaddfgh",
			dept_name: "gjdtrefawetyetgrshrsjsrsaddfgh",
			vac_date_dose1: "1",
			vac_date_dose2: "2"
		}
	]);
	let btnList = [
		{
			key: "add",
			text: "add"
		}
	];
	const formSchemaTop: FormSchema[] = [
		{
			label: t("felix_ui.doctor_siganature"),
			field: "vac_date_dose1",
			component: "Select",
			componentProps: {
				options: [
					{ label: "1", value: "1" },
					{ label: "2", value: "2" }
				]
			}
		},
		{
			label: t("felix_ui.save"),
			field: "vac_date_dose2",
			component: "Select",
			componentProps: {
				options: [
					{ label: "1", value: "1" },
					{ label: "2", value: "2" }
				]
			}
		}
	];
	const columns: BasicColumn[] = [
		{
			title: t("felix_ui.sq_numb"),
			width: 100,
			dataIndex: "sq_numb",
			render: (text, record, index) => index * 1 + 1 // 设置序号
		},
		{
			title: t("felix_ui.patient_id"),
			dataIndex: "patient_id"
		},
		{
			title: t("felix_ui.full_name"),
			dataIndex: "full_name"
		},
		{
			title: t("felix_ui.gender"),
			dataIndex: "gender"
		},
		{
			title: t("felix_ui.birthyear"),
			dataIndex: "birthyear"
		},
		{
			title: t("felix_ui.phone_numb"),
			dataIndex: "phone_numb"
		},
		{
			title: t("felix_ui.citizen_id"),
			dataIndex: "citizen_id"
		},
		{
			title: t("felix_ui.pat_address"),
			dataIndex: "pat_address"
		},
		{
			title: t("felix_ui.workplace"),
			dataIndex: "workplace"
		},
		{
			title: t("felix_ui.dept_name"),
			dataIndex: "dept_name"
		},
		{
			title: t("felix_ui.vac_date_dose1"),
			dataIndex: "vac_date_dose1"
		},
		{
			title: t("felix_ui.vac_date_dose2"),
			dataIndex: "vac_date_dose2"
		}
	];
	const dataApi = () => {
		return data;
	};
	const [register, { getFieldsValue, resetFields }] = useForm({
		schemas: formSchemaTop,
		labelWidth: 120,
		showActionButtonGroup: true
	});
	const [formTop, { reload }] = useTable({
		dataSource: dataApi(),
		columns,
		useSearchForm: false
	});
	const selectFn = async () => {
		const res = await getFieldsValue();
		const { vac_date_dose1, vac_date_dose2 } = res;
		temporarily = data;
		if (vac_date_dose1 && vac_date_dose2) {
			let arr = data.map(item => {
				if (item.vac_date_dose1 === vac_date_dose1 && item.vac_date_dose2 === vac_date_dose2) return item;
			});
			arr.filter(element => element !== undefined);
			setData(arr);
			reload();
			return;
		}
		if (vac_date_dose1) {
			let arr = data.map(item => {
				if (item.vac_date_dose1 === vac_date_dose1) return item;
			});
			arr.filter(element => element !== undefined);
			console.log(arr);
			setData(arr);
			reload();
			return;
		}
		if (vac_date_dose2) {
			let arr = data.map(item => {
				if (item.vac_date_dose2 === vac_date_dose2) return item;
			});
			arr.filter(element => element !== undefined);
			setData(arr);
			reload();
			return;
		}
	};
	const resetFn = () => {
		setData(temporarily);
		reload();
		resetFields();
	};
	const [registerDrawer, { openDrawer: creata }] = useDrawer();
	const addFn = (value: any) => {
		console.log(value);
		setData([...data, value]);
	};
	const handlerToolbarAction = (key: string) => {
		switch (key) {
			case "add":
				creata(true, {
					reload,
					addFn
				});
				break;
		}
	};

	return (
		<div className="vaccination_certificate page">
			<div className=" page-content">
				<div className="headerSelect mb-3">
					<h3>Ⅰ、{t("kevin_ui.filter")}</h3>
					<div className="headerSelectForm">
						<div className="form">
							<BasicForm register={register} submit={selectFn} reset={resetFn}></BasicForm>
						</div>
					</div>
				</div>
				<div className="headerSelect">
					<h3>Ⅱ、{t("kevin_ui.vaccination")}</h3>
					<BasicTable register={formTop}></BasicTable>
				</div>
				<CreareVaccinate register={registerDrawer}></CreareVaccinate>
			</div>
			<Toolbar action={handlerToolbarAction} btnList={btnList} />
		</div>
	);
}
